qrisp.QuantumFloat.sign#
- QuantumFloat.sign()[source]#
Returns the sign qubit.
This qubit is in state \(\ket{1}\) if the QuantumFloat holds a negative value and in state \(\ket{0}\) otherwise.
For more information about the encoding of negative numbers check the publication.
Warning
Performing an X gate on this qubit does not flip the sign! Use inplace multiplication instead.
>>> from qrisp import QuantumFloat >>> qf = QuantumFloat(3, signed = True) >>> qf[:] = 3 >>> qf *= -1 >>> print(qf) {-3: 1.0}
- Returns:
- Qubit
The qubit holding the sign.
- Raises:
- Exception
Tried to retrieve sign qubit of unsigned QuantumFloat.
Examples
We create a QuantumFloat, initiate a state that has probability 2/3 of being negative and entangle a QuantumBool with the sign qubit.
>>> from qrisp import QuantumFloat, QuantumBool, cx >>> qf = QuantumFloat(4, signed = True) >>> n_amp = 1/3**0.5 >>> qf[:] = {-1 : n_amp, -2 : n_amp, 1 : n_amp} >>> qbl = QuantumBool() >>> cx(qf.sign(), qbl) >>> print(qbl) {True: 0.6667, False: 0.3333}